package com.study.jyg.rxjava2study.activity;

import com.google.android.material.textfield.TextInputEditText;

import android.util.Log;
import android.widget.Button;
import android.widget.LinearLayout;

import com.rxjava.rxlife.RxLife;
import com.study.jyg.rxjava2study.R;
import com.study.jyg.rxjava2study.api.Urls;
import com.study.jyg.rxjava2study.base.BasicActivity;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import rxhttp.wrapper.param.RxHttp;

public class LoginActivity extends BasicActivity {


    @BindView(R.id.editAdmin)
    TextInputEditText editAdmin;
    @BindView(R.id.editPwd)
    TextInputEditText editPwd;
    @BindView(R.id.linearLayout)
    LinearLayout linearLayout;
    @BindView(R.id.btnLogin)
    Button btnLogin;

    @Override
    protected int getLayout() {
        return R.layout.activity_login;
    }

    @Override
    protected boolean isUseThemestatusBarColor() {
        return false;
    }

    @Override
    protected void initView() {

        btnLogin.setOnClickListener(v -> login());
    }

    private void login() {
        startActivity(MainActivity.class);
        finish();
//        startActivity(TestActivity.class);
//        Map<String, Object> map = new HashMap<>();
//        String admin = editAdmin.getText().toString();
//        String pwd = editPwd.getText().toString();
//                RxHttp.postForm(Urls.DEMO)
//                        .add("phone", admin)
//                        .add("password", pwd)
//                        .from()
//                        .as(RxLife.asOnMain(this))//如果当前界面关闭，自动中断请求
//                        .subscribe(s -> {
//                            Log.e("RxHttp", "Sucess:"+ s);
//
//                            finish();
//                        }, throwable -> {
//                            Log.e("RxHttp", "Error:");
//                        });
    }
    private void upLoadFile() {
        Map<String, Object> map = new HashMap<>();
//        map.put("types", 0);
//        map.put("renames", );
//        map.put("zhanghao", );
//        map.put("code", );
//        map.put("skewm", );

                RxHttp.postForm(Urls.DEMO_FILE)
                        .setHeader("X-Token", "")
                        .from()
                        .as(RxLife.asOnMain(() -> null))//如果当前界面关闭，自动中断请求
                        .subscribe(s -> {
                            Log.e("RxHttp", "Sucess:"+ s);
                            startActivity(MainActivity.class);
                            finish();
                        }, throwable -> {
                            Log.e("RxHttp", "Error:");
                        });
    }


}
